package ua.eug.airv1.utils;

import ua.eug.airv1.orders.EOrder;

public enum EDirection {
	N(0), NEE(302), SEE(238), S(180), SWW(122), NWW(58); // values depend of hex shape
	
	private int angle;
	
	EDirection(int a) {
		angle = a;
	}
	
	public EDirection getNext(EOrder o) {
		if ( o==EOrder.LEFT || o==EOrder.RIGHT )
			switch (this) {
			case N:
				return (o==EOrder.LEFT)?NWW:NEE;
			case NEE:
				return (o==EOrder.LEFT)?N:SEE;
			case NWW:
				return (o==EOrder.LEFT)?SWW:N;
			case S:
				return (o==EOrder.LEFT)?SEE:NWW;
			case SEE:
				return (o==EOrder.LEFT)?NEE:S;
			default: // SWW
				return (o==EOrder.LEFT)?S:NWW;
			}
		else
			return this;
	}
	
	public EOrder getTurn(EDirection d2) {
		if (d2 == this) return EOrder.STRAIGHT;
		
		switch (this) {
		case N:
			if (d2 == NWW)
				return EOrder.LEFT;
			else if (d2 == NEE)
				return EOrder.RIGHT;
			break;
		case NEE:
			if (d2 == N)
				return EOrder.LEFT;
			else if (d2 == SEE)
				return EOrder.RIGHT;
			break;
		case NWW:
			if (d2 == SWW)
				return EOrder.LEFT;
			else if (d2 == N)
				return EOrder.RIGHT;
			break;
		case S:
			if (d2 == SEE)
				return EOrder.LEFT;
			else if (d2 == NWW)
				return EOrder.RIGHT;
			break;
		case SEE:
			if (d2 == NEE)
				return EOrder.LEFT;
			else if (d2 == S)
				return EOrder.RIGHT;
			break;
		default: // SWW
			if (d2 == S)
				return EOrder.LEFT;
			else if (d2 == NWW)
				return EOrder.RIGHT;
		}
		return EOrder.NONE;
	}
	
	public int getAngle() {
		return angle;
	}
}
